# Problem 17
#
# If the numbers 1 to 5 are written out in words: one, two, three, four, five,
# then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
#
# If all the numbers from 1 to 1000 (one thousand) inclusive were written out
# in words, how many letters would be used? 
#
# NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and
# forty-two) contains 23 letters, and 115 (one hundred and fifteen) contains
# 20 letters. The use of "and" when writing out numbers is in compliance with
# British usage.

single = {  1 : "one",
            2 : "two",
            3 : "three",
            4 : "four",
            5 : "five",
            6 : "six",
            7 : "seven",
            8 : "eight",
            9 : "nine" }

teens  = { 10 : "ten",
           11 : "eleven",
           12 : "twelve",
           13 : "thirteen",
           14 : "fourteen",
           15 : "fifteen",
           16 : "sixteen",
           17 : "seventeen",
           18 : "eighteen",
           19 : "nineteen" }

tens   = { 20 : "twenty",
           30 : "thirty",
           40 : "forty",
           50 : "fifty",
           60 : "sixty",
           70 : "seventy",
           80 : "eighty",
           90 : "ninety" }

other  = { 100 : "hundred",
          1000 : "thousand" }


# sum up from 1 to 19
# from 20 - 1000, loop
# for one's digit: iff non-zero find from single
# for ten's digit: iff non-zero find from tens
# for hundred's digit: iff find from single, add "hundred", add "and" iff there is a ten's or one's value
# sum up for 1000
answer = ""
answer += "".join(single.values())
answer += "".join(teens.values())

for i in range (20,100,10):
    answer += tens[i]
    for j in range(1,10):
        answer += tens[i] + single[j]
    
for i in range(100,1000,100):
    h = single[i/100]
    answer += h + "hundred"
    for j in range(1,10):
        answer += h + "hundredand" + single[j]
    for j in range(10,20):
        answer += h + "hundredand" + teens[j]
    for j in range(20,100,10):
        answer += h + "hundredand" + tens[j]
        for k in range(1,10):
            answer += h + "hundredand" + tens[j] + single[k]

answer += "onethousand"

print "-> ", len(answer)
